package hos.ksl

import android.annotation.SuppressLint
import android.text.InputType
import android.text.method.DigitsKeyListener
import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import android.widget.EditText
import android.widget.TextView


/**
 * <p>Title: TextViewKsl </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @date : 2024-08-12 14:48
 * @version : 1.0
 */
fun EditText.showPassword() {
    transformationMethod = HideReturnsTransformationMethod.getInstance()
    setSelection(getText().length)
}

fun EditText.hidePassword() {
    transformationMethod = PasswordTransformationMethod.getInstance()
    setSelection(getText().length)
}

fun EditText.onlyNumberWord() {
    setKeyListener(
        DigitsKeyListener.getInstance("0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM")
    )
    setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
}

@SuppressLint("SetTextI18n")
fun TextView.clearText() {
    text = ""
}

fun TextView.getString(): String {
    if (text == null || text.isEmpty()) {
        return ""
    }
    val value = text.toString()
    if (value == "null" || value == "NULL" || value == "Null") {
        return ""
    }
    return value
}